package com.fuyu.system.models.form;

import com.fuyu.common.web.validation.group.AddGroup;
import com.fuyu.common.web.validation.group.EditGroup;
import com.fuyu.system.entity.SysUser;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import lombok.Data;

@Data
public class SysUserForm {
    //用户ID
    @Schema(description = "用户ID")
    @NotNull(message = "用户id不能为空", groups = {EditGroup.class})
    @Null(message = "用户id必须为空", groups = {AddGroup.class})
    private Long userId;


    //部门ID
    @Schema(description = "部门ID")
    @NotNull(message = "部门ID不能为空")
    private Long deptId;


    @Schema(description = "用户名")
    @NotBlank(message = "用户名不能为空")
    private String username;


    //密码
    @Schema(description = "密码")
    @NotBlank(message = "密码不能为空")
    private String password;
    //用户昵称
    @Schema(description = "用户昵称")
    @NotBlank(message = "用户昵称不能为空")
    private String nickname;

    //头像路径
    @Schema(description = "头像路径")
    private String avatar;

    //用户邮箱
    @Schema(description = "用户邮箱")
    private String email;
    //手机号码
    @Schema(description = "手机号码")
    private String phone;
    //用户性别（0男 1女 2未知）
    @Schema(description = "用户性别（0男 1女 2未知）")
    @NotBlank(message = "用户性别不能为空")
    private String gender;
    //盐加密
    @Schema(description = "盐加密")
    private String salt;
    //帐号状态（0正常 1停用）
    @Schema(description = "帐号状态（0正常 1停用）")
    @NotBlank(message = "帐号状态不能为空")
    private String status;

    //备注
    @Schema(description = "备注")
    private String remark;


    public SysUser toEntity(SysUserForm sysUserForm) {
        SysUser sysUser = new SysUser();
        sysUser.setUserId(sysUserForm.getUserId());
        sysUser.setDeptId(sysUserForm.getDeptId());
        sysUser.setPassword(sysUser.getPassword());
        sysUser.setNickname(sysUserForm.getNickname());
        sysUser.setAvatar(sysUserForm.getAvatar());
        sysUser.setEmail(sysUserForm.getEmail());
        sysUser.setPhone(sysUserForm.getPhone());
        sysUser.setGender(sysUserForm.getGender());
        sysUser.setSalt(sysUserForm.getSalt());
        sysUser.setStatus(sysUserForm.getStatus());
        sysUser.setRemark(sysUserForm.getRemark());
        return sysUser;
    }
}
